package com.zhuoyue.biz.core.api.dto.rep;

import com.zhuoyue.biz.core.api.domain.HomeDO;
import com.zhuoyue.biz.core.api.domain.home.HomeFistReqDO;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author wjming
 * @ClassName: HomeRepDTO
 * @Description: 家庭信息回应对象信息
 * @Date 2021-07-01 9:04
 */
@Data
public class HomeRepDTO extends BaseRepDTO {
    /**
     * 家庭名称
     */

    private String name;

    /**
     * 家庭位置（省市区）
     */
    private String location;

    /**
     * 家庭地址（详细地址）
     */
    private String address;
    /**
     * 经度
     */
    private Double longitude;
    /**
     * 维度
     */
    private Double latitude;

    /**
     * 图片地址
     */

    private String imgUrl;

    private List<GatewayRepDTO> gatewayList;


    private Integer RoomCount;
    private Integer DeviceCount;

    /**
     * 用户和家庭的关系 0：主人；1：分享
     */

    private Integer appUserHomeRelation;

    /**
     * 添加家庭的数据信息返回到DTO上
     *
     * @param home
     * @return
     */
    public HomeRepDTO homeDoToHomeRepDto(HomeDO home) {
        setId(home.getId());
        setCreateTime(home.getCreateTime());
        this.name = home.getName();
        this.location = home.getLocation();
        this.address = home.getAddress();
        this.imgUrl = home.getImgUrl();
        this.gatewayList = null;
        this.RoomCount = 3;
        this.DeviceCount = 0;
        this.appUserHomeRelation = 0;
        this.longitude = home.getLongitude();
        this.latitude = home.getLatitude();
        return this;
    }

    /**
     * 用户第一次请求进来时候所要返回的对象信息
     *
     * @param homeFistReqDO
     * @param gatewayRepDTO
     * @return
     */
    public HomeRepDTO homeFistReqDoToHomeRepDto(HomeFistReqDO homeFistReqDO, List<GatewayRepDTO> gatewayRepDTO) {
        setId(homeFistReqDO.getId());
        setCreateTime(homeFistReqDO.getCreateTime());
        this.name = homeFistReqDO.getName();
        this.location = homeFistReqDO.getLocation();
        this.address = homeFistReqDO.getAddress();
        this.imgUrl = homeFistReqDO.getImgUrl();
        this.gatewayList = CollectionUtils.isEmpty(gatewayRepDTO) ? Collections.emptyList() : gatewayRepDTO;
        this.RoomCount = homeFistReqDO.getRoomCount();
        this.DeviceCount = homeFistReqDO.getDeviceCount();
        this.appUserHomeRelation = homeFistReqDO.getRelationType();
        this.longitude = homeFistReqDO.getLongitude();
        this.latitude = homeFistReqDO.getLatitude();
        return this;
    }
}
